<template>
    <div>
        <a-modal width="55%" v-model="visible" :title="modelTitle">
            <template slot="footer">
                <a-button @click="handleCancel">
                    取消
                </a-button>
                <a-popconfirm overlayClassName="poperLayTable" title="确定发送吗?" @confirm="() => handleSend()">
                    <a-button type="primary">
                        发送
                    </a-button>
                </a-popconfirm>
            </template>
            <a-form-model :model="formData" :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-form-model-item v-for="item in dataSource" :label="item.label" :key="item.grid">
                    <a-input v-model="formData[item.key]" placeholder="请输入">
                    </a-input>
                </a-form-model-item>
            </a-form-model>
        </a-modal>
    </div>
</template>

<script>
import { httpAction } from '../../../../api/manage'
export default {
    data() {
        return {
            visible: false,
            labelCol: { span: 4 },
            wrapperCol: { span: 14 },
            dataSource: [],
            formData: {},
            record: {},
            modelTitle: '',
            url: {
                sendPackage: '/channel/nmcChannelInfo/sendPackage'
            }
        }
    },
    methods: {
        showModal(record) {
            this.visible = true
            this.record = record
            this.dataSource = record.paramList
            this.modelTitle = record.packName + '参数配置'

        },
        handleCancel() {
            this.visible = false
            this.resetForm()
        },
        handleSend() {
            // console.log(123);
            let data = {
                packageCode: this.record.packCode,
                nmcPackageGridValues: [],

            }
            this.dataSource.forEach(i => {
                data.nmcPackageGridValues.push({ gridCode: i.grid, packageGridValue: this.formData[i.key] })
            })
            console.log(data, '---发送包参数')
            httpAction(this.url.sendPackage, data, 'post').then(res => {
                if (res.success) {
                    this.$message.success(res.success)
                } else {
                    this.$message.error(res.success)
                }
            })
            this.visible = false
            this.resetForm()
        },
        resetForm() {

            this.formData = {}
        },
    }

}
</script>

<style></style>